subroutine set_space_vectors()

  use dimensions
  use mpi_wrap
  use fft_wrap,   only  : fft_forward, fft_backward

  use parameters, only : kz, nz, Lx, Ly, vPhase, Vmax, iWaveFrame, pi

  implicit none


  integer              :: ix, iy, iz, iv       ! counters in r-space
  integer              :: ikx, iky, ikz, ikv   ! counters in k-space
  

  write(msg,*) char(10), ' Creating space vectors'
  call mpi_wrap_msg


      !--  setting spectral and spatial resolution --

      dkz = kz/nz
      dz  = 2*pi/(jz*dkz)       

      dx  = Lx/jx
      dkx = 2*pi/Lx

      dy  = Ly/jy
      dky = 2*pi/Ly
      
      dv  = 2*Vmax/jv
      dkv = 2*pi/(2*Vmax)


      !-- dimension vectors in r-space --

      do ix=1,jx
         xvec(ix) = -Lx/2 + dx * (ix-1)
      enddo

      do iy=1,jy
         yvec(iy) = -Ly/2 + dy * (iy-1)
      enddo

      do iz=1,jz
         zvec(iz) = (iz-1)*dz
      enddo    

      do iv=1,jv
         vvec(iv) = -vPhase*iWaveFrame - Vmax + dv*(iv-1)
      end do
      

      !-- dimension vectors in k-space --

      kXvec(jx)=-dkx
      do ikx=jx-1,jx/2+2,-1
         kXvec(ikx)=kXvec(ikx+1)-dkx
      end do
      kXvec(1)=0.0
      do ikx=2,jx/2+1
         kXvec(ikx)=kXvec(ikx-1)+dkx
      end do

      kYvec(jy)=-dky
      do iky=jy-1,jy/2+2,-1
         kYvec(iky)=kYvec(iky+1)-dky
      end do
      kYvec(1)=0.0
      do iky=2,jy/2+1
         kYvec(iky)=kYvec(iky-1)+dky
      end do

      kZvec(jz)=-dkz
      do ikz=jz-1,jz/2+2,-1
         kZvec(ikz)=kZvec(ikz+1)-dkz
      end do
      kZvec(1)=0.0
      do ikz=2,jz/2+1
         kZvec(ikz)=kZvec(ikz-1)+dkz
      end do

      kVvec(jv)=-dkv
      do ikv=jv-1,jv/2+2,-1
         kVvec(ikv)=kVvec(ikv+1)-dkv
      end do
      kVvec(1)=0.0
      do ikv=2,jv/2+1
         kVvec(ikv)=kVvec(ikv-1)+dkv
      end do

end subroutine set_space_vectors


!-------------------------------------------------------------------------------------
! subroutine deAlias
!-------------------------------------------------------------------------------------

subroutine deAlias(jz,et)

  use parameters, only : iDealias

  implicit none

  integer i,jz;  
  complex et(jz)

  if (jz<6) return

  if (iDealias)   et(jz/2-jz/6 : jz/2+2+jz/6) = (0.0,0.0)

  return

end

!-------------------------------------------------------------------------------------
subroutine set_filter(filter)
!-------------------------------------------------------------------------------------

  use dimensions

  use parameters, only :  kFilterAngle

  implicit none

  real,    intent(out) :: filter(jz,jy,jx)
  real                 :: kk, tantheta
  integer              :: ikx, iky, ikz

      filter=1.0
      tantheta = tan(kFilterAngle)

      do ikx=1,jx
         do iky=1,jy
            do ikz=1,jz
               kk = (kXvec(ikx))**2 + (kYvec(iky))**2 
               !if( kk > kFilter**2 ) filter(ikz,iky,ikx) = 0   !cylindrical
               if( kk > (kZvec(ikz)*tantheta)**2 ) filter(ikz,iky,ikx) = 0   !conical
            enddo
         end do
      end do

end subroutine set_filter

!-------------------------------------------------------------------------------------
